<template>
  <el-dialog class="pick-dialog" title="完成订单" :visible.sync="dialogVisible" :close-on-click-modal="false" width="800px">
    <div class="form-box">
      <el-form :model="ruleForm" ref="ruleForm" label-width="auto" :rules="rules" class="demo-ruleForm">
        <el-form-item label="真实游戏账号:" prop="realAccountNumber">
          <el-input placeholder="请输入真实游戏账号" type="text" style="width: 200px;" v-model="ruleForm.realAccountNumber"></el-input>
        </el-form-item>
        <el-form-item label="换绑手机:" prop="changeTel">
          <el-input placeholder="请输入换绑手机" type="text" style="width: 200px;" v-model="ruleForm.changeTel"></el-input>
        </el-form-item>
        <el-form-item label="备注:" prop="">
          <el-input placeholder="请输入订单备注" type="textarea" rows="5" style="width: 600px;" v-model="ruleForm.remark"></el-input>
        </el-form-item>
        <!-- <div class="tip">提示： <span >如果订单是在线支付的订单，交易完成后系统会自动进行买家和卖家的订单结算。</span> </div> -->
      </el-form>

      <div class="center">
        <el-button @click="close('ruleForm')">关闭</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')" :loading="loading">确认完成</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import orderApi from "@/api/pickUp/order";
import { mapGetters } from "vuex";
export default {
  name: "pick",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      reasonList: [
        {
          label: "不想买了",
          value: "1",
        },
        {
          label: "描述不符",
          value: "2",
        },
        {
          label: "协商取消",
          value: "3",
        },
      ],
      ruleForm: {
        realAccountNumber: "",
        remark: "",
        id: "",
        changeTel: "",
      },
      rules: {
        realAccountNumber: [
          { required: true, message: "请输入真实游戏账号", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  created() {},
  methods: {
    open(row) {
      this.loading = false;
      this.ruleForm.id = row.id;
      this.ruleForm.remark = row.remark;
      this.ruleForm.realAccountNumber = row.realAccountNumber;
      this.ruleForm.changeTel = row.changeTel||''
      // 销售人 订单有则不变 没有则传当前人
      this.ruleForm.saleUserId = row.saleUserId?null:this.userInfo.userId
      this.ruleForm.saleUserNickname = row.saleUserNickname?null:this.userInfo.nickName
      this.dialogVisible = true;
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          orderApi.finishOrder(this.ruleForm).then((res) => {
            this.dialogVisible = false;
            this.loading = false;
            if (res.code == 200) {
              this.$message.success("订单已完成");
              this.$parent.getList();
            }
          });
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },
    close(formName) {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">
.tip {
  padding-left: 110px;
  margin-bottom: 20px;
  span {
    color: red;
  }
}
.demo-ruleForm {
  padding-right: 20px;
}

.center {
  text-align: center;
}

.pick-dialog >>> .el-input--medium input {
  text-align: left;
}
</style>
